package com.c1.client.menu.support;

import com.c1.client.Frame;
import com.c1.client.pan.Pans;
import com.c1.client.menu.item.MItem;
import com.s.S;
import com.s.core.root.data._AllData;
import org.apache.commons.collections.CollectionUtils;

import java.util.Collections;
import java.util.List;

public abstract class SwitchDateSupport extends MItem {
    protected void switchDate(boolean isNext) {
        String oldDate = Pans.me().getCurrentPan().date(false);
        String date = S.serverData.date(isNext, oldDate);
        String code = Pans.me().getCurrentPan().code(false);
        if (isNext && oldDate.equals(date)) {
            return;
        }
        int showPicNIndex = Pans.me().getCurrentPan().getPicNNextIndex();
        int showPicIndex = Pans.me().getCurrentPan().getPicNextIndex();
        List<_AllData> allDataList = S.serverData.data(Collections.singletonList(code), date);
        if (CollectionUtils.isEmpty(allDataList)) {
            return;
        }
        Pans.me().getCurrentPan().setAllData(allDataList.get(0));
        Pans.me().getCurrentPan().setPicNNextIndex(showPicNIndex);
        Pans.me().getCurrentPan().setPicNextIndex(showPicIndex);

        Pans.me().getCurrentPan().posNNextIndex();

        Frame.me().setTitle(Pans.me().titleMessage());
    }
}
